package com.hongbao.game.controller;

import com.hongbao.game.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("test")
public class TestController {

    @Autowired
    HttpServletRequest request;
    @PostMapping("login")
    public void login(@RequestBody Map loginForm){

        String authorization = request.getHeader("Authorization");
        System.out.println(authorization);
        System.out.println(loginForm);
        //生成token
    }

    @Autowired
    RedisTemplate redisTemplate;

    /**
     * 测试准备数据
     */
    @GetMapping("data")
    public void data(){

        //活动开始之前将 用户的抽奖规则存入Redis
        Long gameId = 1L;
        redisTemplate.opsForHash().put("game_limit_" + gameId,"1",2);//普通用户抽中2次
        redisTemplate.opsForHash().put("game_limit_" + gameId,"2",5);//VIP用户抽中5次


        /**
         * 以下操作用户登录后存入redis
         */
        User user1 = new User(1L,"张三普通用户",1);
        User user2 = new User(2L,"李四VIP用户",2);
        redisTemplate.opsForValue().set("token_zhangsan",user1);
        redisTemplate.opsForValue().set("token_lisi",user2);

    }
}
